package previous.Test_0320;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */

public class Bridge_Blue {
    //迷宫
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        Long[][] num=new Long[31][51];
        for (int i = 0; i < 30; i++) {
            String line = scan.nextLine();
            for (int j = 0; j < 50; j++) {
                num[i][j] = Long.parseLong(line.substring(j, j + 1), 2);
            }
        }
        boolean[][] vis=new boolean[31][51];
        Queue<int[]> q=new LinkedList<>();
        q.add(new int[]{0,0});
        long step=0;
        int[] dx={0,0,1,-1};
        int[] dy={1,-1,0,0};
       while(!q.isEmpty()){
           int[] t=q.poll();
            int a=t[0];
            int b=t[1];
            step++;
           if(a==29 || b==49) break;
            vis[a][b]=true;
                for (int j = 0; j < 4; j++) {
                    int x=dx[j]+a;
                  int y=dy[j]+b;
                   if(x>=0 && x<30 && y>=0 && y<50 && !vis[x][y] && num[x][y]!=1){
                       q.add(new int[]{x,y});

                   }

                }
        }
        System.out.println(step);
       //在此输入您的代码...
       scan.close();
   }

}








